﻿@using XStudio.XCRF.Data.Entities.CureInfo
@using XStudio.XCRF.Resources.Entities
@using XStudio.XCRF.Resources.Entities.CureInfo
@model CRF
@(Html.Telerik().Grid<CureInfo>()
    .Name("CureInfoViewGrid")
    .ToolBar(config =>
    {
        if (LoginSession.IsAdministrator)
            config.Custom().Name("Add").Text("添加新治疗信息").Action<CureInfoController>(c => c.CureInfoAdd(null));
    })
    .DataKeys(keys => keys.Add(cure => cure.ID))
    .Columns(columns =>
    {
        columns.Bound(cure => cure.ID).Hidden();
        columns.BoundDate(cure => cure.Time).Title(CureInfoResource.Time);
        columns.BoundDateTime(cure => cure.LastModifyTime).Title(BaseEntityResource.LastModifyTime);
        columns.Bound(cure => cure.LastModifier.RealName).Title(BaseEntityResource.LastModifier);
        columns.BoundDateTime(cure => cure.CreateTime).Title(BaseEntityResource.CreateTime);
        columns.Bound(cure => cure.Creater.RealName).Title(BaseEntityResource.Creater);
        columns.Command(commands =>
        {
            commands.Custom("Detail").Text("查看详情").Ajax(true);
            commands.Custom("Edit").Text("编辑").Ajax(true);
            commands.Custom("History").Text("历史记录").Ajax(true);
            if (LoginSession.IsAdministrator)
                commands.Delete();
        })
        .Title("操作");
    })
    .ClientEvents(events =>
    {
        events.OnCommand("OnCureInfoCommand");
    })
    .DataBinding(bind =>
    {
        bind.Ajax()
            .Select<CRFController>(c => c.CureInfoGridList(Model.ID))
            .Delete<CRFController>(c => c.CureInfoDelete(null));
    })
    .Pageable(pager => pager.PageSize(10).Style(GridPagerStyles.NextPreviousAndNumeric))
    .Filterable(filtering => filtering.Enabled(true))
    .Editable(edit => edit.Mode(GridEditMode.InLine))
    .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn).OrderBy(ord => ord.Add(o => o.CRFID)))
)
<script type="text/javascript">
    function CureInfoDetail(id) {
        var url = "@(Url.Action<CureInfoController>(c => c.CureInfoDetail(Guid.Empty)))";
        url = url.replace("@Guid.Empty", id);
        window.location = url;
    }
    function CureInfoEdit(id) {
        var url = "@(Url.Action<CureInfoController>(c => c.CureInfoEdit(Guid.Empty)))";
        url = url.replace("@Guid.Empty", id);
        window.location = url;
    }
    function CureInfoHisList(id) {
        var url = "@(Url.Action<CureInfoController>(c => c.CureInfoHisGridList(Guid.Empty)))";
        url = url.replace("@Guid.Empty", id);
        window.location = url;
    }
    function OnCureInfoCommand(e) {
        switch (e.name) {
            case "Detail": CureInfoDetail(e.dataItem.ID); break;
            case "Edit": CureInfoEdit(e.dataItem.ID); break;
            case "History": CureInfoHisList(e.dataItem.ID); break;
        }
    }
</script>